from inputdata import *     # 读取参数模块
from wall_1D import *       # 墙体模块
from boundary import *      # 边界条件模块
'''该模块负责计算前处理'''


# 从文件中读取数据参数
def load_sourcedata(file_type):
    if file_type == 'xlsx':   # 从xlsx文件读取数据
        parameters = readdata_xlsx()
    else:
        print('文件类型不正确！')
        raise FileNotFoundError
    return parameters


# 将读取的原始参数处理成为计算的参数
def load_parameters(file_type):
    # 读取参数
    basic, wall, origin, boundary = load_sourcedata(file_type)
    # 1.基本参数处理
    time_now, time_step, time_count, loop_count, max_error = basic    # 返回基本参数

    # 2.墙体参数处理
    layersName, layersLength, layersGrid = wall  # 返回墙体参数

    s_coe_all, x_step = create_walls(layersName, layersLength, layersGrid)
    x_grid = len(x_step)

    # 3.初始条件处理
    field_t, field_rh = origin        # 返回初始条件

    if len(field_t) == 1:
        field_t = np.full(x_grid, field_t[0], dtype=float)
        field_rh = np.full(x_grid, field_rh[0], dtype=float)
    elif len(field_t) == 2:
        field_t = np.linspace(field_t[0], field_t[1], x_grid, dtype=float)
        field_rh = np.linspace(field_rh[0], field_rh[1], x_grid, dtype=float)
    else:
        pass
    # 原始温湿度单位为℃，%；转化为K，1
    field_tk = np.array(field_t) + 273.15
    field_rh = np.array(field_rh) / 100

    # 4.边界条件处理
    boundary_out, boundary_in = np.array(boundary)    # 返回边界条件(包括时间)
    boundary_out[1] += 273.15  # 温度处理
    boundary_in[1] += 273.15
    boundary_out[2] /= 100   # 湿度处理
    boundary_in[2] /= 100

    # 返回计算所需参数
    return time_step, time_count, loop_count, max_error,\
            s_coe_all, x_step, time_now, field_tk, field_rh, boundary_out, boundary_in


if __name__ == '__main__':
    a = load_parameters('xlsx')
